# coding=utf-8
#


from django.db import models

from iminer.ecs.models import ECS


class ActionLog(models.Model):
    """ 操作日志, 对每一台机器进行操作的记录 """
    ATYPE_CHOICES = ((1, "启动"),
                     (2, "初始化"),
                     (3, "重启"),
                     (5, "重装"),
                     (10, "销毁"))

    STATUS_CHOICES = ((2, "未开始"),
                      (1, "处理中"),
                      (0, "处理完成"),
                      (-10, "处理失败"))

    ecs = models.ForeignKey(ECS, verbose_name="被操作实例",
                            on_delete=models.SET_NULL, null=True, blank=True)
    atype = models.IntegerField(choices=ATYPE_CHOICES, verbose_name="操作类型", default=0)
    content = models.TextField(default="", verbose_name="操作内容")
    status = models.IntegerField(default=2, verbose_name="操作日志运行结果", choices=STATUS_CHOICES)
    create_time = models.DateTimeField(auto_now=False, auto_now_add=True, verbose_name="创建时间")
    update_time = models.DateTimeField(auto_now=True, verbose_name="修改时间")

    class Meta:
        ordering = ("-create_time",)
        verbose_name = "操作日志"
        verbose_name_plural = "操作日志管理"

    def __str__(self):
        return "ECS: %s, Action: %s" % (self.ecs, self.atype)

